package com.duanjw.bank.rate.core;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author duanjw
 * @date 2024/4/7
 */
public class DateFormatUtil {
    public static LocalDate format1(String input){
        Pattern pattern = Pattern.compile("(\\d{4}.\\d{1,2}.\\d{1,2})");
        Matcher matcher = pattern.matcher(input);
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy.MM.dd");
        if (!matcher.find()) {
            return null;
        }
        return LocalDate.parse(matcher.group(0), dateTimeFormatter);
    }
    public static LocalDate format2(String input){
        Pattern pattern = Pattern.compile("(\\d{4}年\\d{1,2}月\\d{1,2}日)");
        Matcher matcher = pattern.matcher(input);
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年M月d日");
        if (!matcher.find()) {
            return null;
        }
        return LocalDate.parse(matcher.group(0), dateTimeFormatter);
    }
    public static LocalDate format3(String input){
        Pattern pattern = Pattern.compile("(\\d{4}-\\d{1,2}-\\d{1,2})");
        Matcher matcher = pattern.matcher(input);
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-M-d");
        if (!matcher.find()) {
            return null;
        }
        return LocalDate.parse(matcher.group(0), dateTimeFormatter);
    }
}
